package model.collisions2d;


public class BoxMask{
	private final double left,right,top,bot;
	
	/**
	 * A Mask which masks a box area
	 * @param left
	 * @param right
	 * @param top
	 * @param bottom
	 * @require left<right && top<bottom
	 */
	public BoxMask(double left,double top, double right, double bottom){
		this.left=left;
		this.right=right;
		this.top=top;
		this.bot=bottom;
	}
	
	public boolean isInsideMask(double x,double y){
		return (x>=getLeft() && x<getRight()) && (y>=getTop() && y<getBottom());
	}
	
	public boolean isInsideMask(BoxMask m){
		return 	isInsideMask(m.getLeft(),m.getTop()) ||
				isInsideMask(m.getRight(),m.getTop()) ||
				isInsideMask(m.getLeft(),m.getBottom()) ||
				isInsideMask(m.getRight(),m.getBottom());
	}
	
	/**
	 * Checks if a BoxMask overlaps this BoxMask when it is moved by a given offset
	 * @param m the other mask
	 * @param xoffset the x offset of the other mask relative to this mask
	 * @param yoffset the y offset of the other mask relative to this mask
	 * @return true if the masks overlap
	 */
	public boolean isInsideMask(BoxMask m,double xoffset,double yoffset){
		return 	isInsideMask(m.getLeft()+xoffset,m.getTop()+yoffset) ||
				isInsideMask(m.getRight()+xoffset,m.getTop()+yoffset) ||
				isInsideMask(m.getLeft()+xoffset,m.getBottom()+yoffset) ||
				isInsideMask(m.getRight()+xoffset,m.getBottom()+yoffset);
	}
	
	protected double getLeft(){
		return left;
	}
	
	protected double getRight(){
		return right;
	}
	
	protected double getTop(){
		return top;
	}
	
	protected double getBottom(){
		return bot;
	}
	
	public MultipleBoxMask getMultipleBoxMask(){
		return new MultipleBoxMask(this);
	}
}
